Multithread-Safe, MT-Safe

C++11이전 버전에서는 이중 검증 락킹(double-checked locking)으로 생성자를 보호해야 한다.
struct Database{
static Database& instance();
private:
static boost::atomic<Database*> instance;
static boost::mutex mtx;
};
Database& Database::instance(){
Database* db=instance.load(boost::memory_order_consume);
if(!db){
boost::mutex::scoped_lock lock(mtx);
db=instance.load(boost::memory_order_consume);
if(!db){
db=new Database();
instance.store(db, boost::memory_order_release);
}
}
}